{include file="default/base/header" /}

<link rel="stylesheet" href="{$Think.PLUGINS_SITE_ROOT}/js/jquery.lightbox/css/lightbox.min.css">
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery.lightbox/js/lightbox.min.js"></script>
<div class="page" style="min-height: 300px;">

    <form id="goods_class_form" method="post" action=''>
        <table class="ds-default-table">
            <tbody>
            <tr class="noborder" style="background: rgb(255, 255, 255);">
                <td class="required w120"><label class="validation">方案名称:</label></td>
                <td class="vatop rowform">
                    <input style="width: 233px;" type="text"  name="scheme_name" id="scheme_name" class="txt">
                </td>
                <td class="vatop tips"></td>
            </tr>

            <tr class="noborder" style="background: rgb(255, 255, 255);">
                <td class="required w120"><label class="validation">店铺类型:</label></td>
                <td class="vatop rowform">
                    <select name="inquiry_id" id="inquiry_id" title="">
                        <option value="0">请选择店铺类型</option>
                        {notempty name="store_type"}
                        {foreach name="store_type" item="val"}
                        <option value="{$val.id}">{$val.inquiry_name}</option>
                        {/foreach}
                        {/notempty}
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
            <tr class="noborder" style="background: rgb(255, 255, 255);">
                <td class="required w120"><label class="validation">配置类型:</label></td>
                <td class="vatop rowform">
                    <select name="configure" id="configure" title="">
                        <option value="0">请选择配置类型</option>
                        <option value="1">低端配置</option>
                        <option value="2">中端配置</option>
                        <option value="3">高端配置</option>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr>
            <tr style="background: rgb(255, 255, 255);display: none;" id="dation" >
                <td class="required w120"><label class="validation">工位:</label></td>
                <td class="vatop rowform" id="station_ids">
                   <input type="hidden" value=""  name="add_station" id="add_station"> 
                </td>
                <td class="vatop tips"></td>
            </tr>
            <!-- <tr class="noborder" style="background: rgb(255, 255, 255);">
                <td class="required w120"><label class="validation">工位:</label></td>
                <td class="vatop rowform">
                    <select name="station_id" title="" id="station_ids">
                        <option value="0">请选择工位</option>
                    </select>
                </td>
                <td class="vatop tips"></td>
            </tr> -->
            <tr class="noborder" style="background: rgb(255, 255, 255);">
                <td class="required w120"><label >备注:</label></td>
                
                <td class="vatop rowform onoff">
                  <textarea style="width: 233px;height: 88px;" id="remarks" name="remarks"></textarea>
                </td>
                    
                <td class="vatop tips"></td>
            </tr>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="2">
                        <input style="margin-left: 176px;" class="btn" type="button" onclick="import_inquiry()" value="生成方案" />
                    </td>
                </tr>
            </tfoot>
        </table>
    </form>
</div>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.mousewheel.js"></script>
<script>


    //按钮先执行验证再提交表单
    // $(function() {
    //     $('.btn').click(function(){
    //         // var title = $("input[name='inquiry_name']").val();
    //         // if ( title.length ==0) {
    //         //     alert('店铺分类不能为空');
    //         //     return;
    //         // }
    //         $('#goods_class_form').submit();
    //     });
    // });
</script>

<script>
    $(function (){
        // 动态获取工位
        $('#inquiry_id').change(function(){
            
            var inquiry_id = $(this).val();
            $.ajax({
                type: 'post',
                url: HOMESITEURL + '/Sellerinquiry/get_station',
                data: {'inquiry_id' : inquiry_id},
                dataType: 'json',
                success: function(res) {
                    console.log(res);
                    if(res.code > 0) {
                        var options = '';
                        // $.each(res.data, function(idx, obj) {
                        //     options += "<option value='"+ obj.station_id +"'>" + obj.station_name +"</option>"

                        // '<input type="text"   name="num" id="num" class="txt" value="'+obj.station_name+'">'  
                        // });
                        $('#dation').show();
                        $.each(res.data, function(idx, obj) {
                            options += obj.station_name + ': &nbsp; 数量: ' + '<input type="text" style="width: 135px;" value="0"  name="num" id="num" class="txt">'+'<br>'  
                            $('#add_station').val(obj.station_id);
                        });
                        $('#station_ids').append(options);

                        
                        // $('#station_ids').empty();
                    } else {
                        $('#station_ids').empty().append('<option value="0">暂无工位选择</option>');
                    }
                },
                error: function () {
                    layer.msg('系统繁忙，请稍后再试！');
                }
            })
        })
    });

    function import_inquiry ()
    {
        var inquiry_id = $('#inquiry_id').val();
        var station_id = $('#station_ids').val();
        var configure = $('#configure').val();
        var scheme_name = $('#scheme_name').val();
        var remarks = $('#remarks').val();
        var add_station = $('#add_station').val();

        if(scheme_name == ''){
            layer.msg('请输入方案名称');
            return false;
        }
        if(inquiry_id == ''){
            layer.msg('请输入店铺类型');
            return false;
        }
        if(configure == ''){
            layer.msg('请输入配置类型');
            return false;
        }
       
        $.ajax({
            type: 'post',
            url: HOMESITEURL + '/Sellerinquiry/import_inquiry',
            data: {'inquiry_id' : inquiry_id,  'station_id': station_id, 'configure': configure,'scheme_name' : scheme_name, 'remarks' : remarks, 'add_station' : add_station},
            dataType: 'json',
            success: function(result) {
                if(result.code==0){
                    layer.msg(result.msg);
                    return false;
                }else{
                    layer.msg(result.msg);
                    parent.location.reload();return false;
                }
            },
            error: function () {
                layer.msg('系统繁忙，请稍后再试！');
            }
        })
    }
</script>
